import {
    GETBANNERS,
    GETTOPLISTS,
    GETLISTDETAIL,
    GETRECOMMENDSONGCARD,
    GETRECOMMENDPROGRAM
} from '../constants';


const INITSTATE = {
    banners: [],
    toplist: [],
    listdetail: [],
    recommendSongcard: [],
    recommendProgram: []
};

export default function (state = INITSTATE, action) {
    const {
        type,
        data
    } = action;
    switch (type) {
        case GETBANNERS:
            let obj1 = makeObj(state);
            obj1.banners = data;
            return obj1;
            break;
        case GETTOPLISTS:
            let obj2 = makeObj(state);
            obj2.toplist = data;
            return obj2;
        case GETLISTDETAIL:
            let obj3 = makeObj(state);
            obj3.listdetail = data;
            return obj3;
        case GETRECOMMENDSONGCARD:
            let obj4 = makeObj(state);
            obj4.recommendSongcard = data;
            return obj4;
        case GETRECOMMENDPROGRAM:
            let obj5 = makeObj(state);
            obj5.recommendProgram = data;
            return obj5;
        default:
            return state; //防止状态丢失
            break;
    }
}

function makeObj(obj) {
    let newobj = {};
    Object.assign(newobj, obj);
    return newobj;
}